package cn.middle.remote.message;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import cn.middle.remote.util.ConversionUtil;

/**
 * 调用下发
 * @author KING
 *
 */
public class CallSignal extends BaseSignal {
	
	private String interfaceName;
	
	//远程目标的客户端标识
	private int remoteAddressClientId;
	
	private byte[] data;

	public int getRemoteAddressClientId() {
		return remoteAddressClientId;
	}

	public void setRemoteAddressClientId(int remoteAddressClientId) {
		this.remoteAddressClientId = remoteAddressClientId;
	}

	public byte[] getData() {
		return data;
	}

	public CallSignal() {
		super(SignalHelper.CALL);
	}

	public String getInterfaceName() {
		return interfaceName;
	}

	public void setInterfaceName(String interfaceName) {
		this.interfaceName = interfaceName;
	}

	public void setData(byte[] data) {
		this.data = data;
	}

	@Override
	public byte[] toData() {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
		DataOutputStream out = new DataOutputStream(bos);
		try {
			out.writeInt(remoteAddressClientId);
			out.write(ConversionUtil.writeStringBytes(interfaceName));
			out.write(ConversionUtil.writeObjectBytes(data));
			out.flush();
			return bos.toByteArray();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new byte[0];
	}

}
